package org.jdns.jfreechess.server;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;

import java.util.Set;
import java.util.logging.Logger;

import javax.inject.Inject;

import com.google.inject.Provider;

class PlayerChannelInitializer extends ChannelInitializer<SocketChannel> {
  private final Logger logger;
  private final Provider<Set<ChannelHandler>> handlers;

  @Inject
  public PlayerChannelInitializer(Provider<Set<ChannelHandler>> handlers, Logger logger) {
    this.handlers = handlers;
    this.logger = logger;
  }

  @Override
  public void initChannel(SocketChannel ch) throws Exception {
    for (ChannelHandler handler : handlers.get()) {
      ch.pipeline().addLast(handler);
    }
    
    logger.info("Pipeline for new user: " + ch.pipeline());
  }
}